Check for certain set of characters¶
Check that a string contains only a certain
set of characters (in this case a-z, A-Z and 0-9).
import re
def is_allowed_specific_char(S):
charRe = re.compile(r'[^a-zA-Z0-9.]')
S = charRe.search(S)
return not bool(S)
# test
print(is_allowed_specific_char("ABCDEFabcdef123450")) # True
print(is_allowed_specific_char("*&%@#!}{")) # False